Open Science Day - KU Leuven
May 6, 2025
An open-source publishing system to combine text and code into formatted output documents
Artwork from “Hello, Quarto” keynote by Julia Lowndes and Mine Çetinkaya-Rundel, presented at RStudio Conference 2022. Illustrated by Allison Horst.
“Friends don’t let friends copy-paste” (Aust & Barth, 2023)
Computational non-reproducibility is a widespread problem:
(Artner et al., 2021; Eubank, 2016; Konkol, Kray & Pfeiffer, 2019)
Quarto can help you make your research more reproducible (same data, same results):
Quarto can also make you more efficient in the long run:
Quarto (R/Python/Julia/Observable to …) is more flexible than alternative solutions:
Artwork from “Hello, Quarto” keynote by Julia Lowndes and Mine Çetinkaya-Rundel, presented at RStudio Conference 2022. Illustrated by Allison Horst.
The ‘quarto’ book format
In your editor, create a .qmd file:
RStudio: File -> New file -> Quarto document
VS Code: File -> New file -> Quarto document
Jupyter: File -> New -> Notebook (creates a .ipynb)
Tip for efficiency
RStudio + VSCode provide rich tab-completion - start a word and tab to complete, or Ctrl + space to see all available options.
quarto renderquarto R packageWarning
In order to create PDFs you will need to install a recent distribution of TeX. We recommend the use of TinyTeX (which is based on TexLive), which you can install with the following command (in the Terminal):
quarto install tinytex
This is a sentence with some bold text, italic text, code, and a link.
More info: https://quarto.org/docs/authoring/markdown-basics.html
Tip for Markdown newbies
New to Markdown? Use the visual editor in RStudio or VS Code!
| Markdown Syntax | Output |
|---|---|
|
italics and bold |
|
superscript2 / subscript2 |
|
|
|
verbatim code |
| Markdown Syntax | Output |
|---|---|
|
Header 1 |
|
Header 2 |
|
Header 3 |
|
Header 4 |
|
Header 5 |
|
Header 6 |
Formula for population mean:
\[ \mu = \frac{\sum x}{N} \]
```{r}
#| label: fig-scatterplot
#| fig-cap: "Scatterplot of flipper and bill lengths"
library(palmerpenguins) # for data
library(tidyverse) # for data wrangling and visualization
library(knitr) # for tables
ggplot(data = penguins,
aes(x = flipper_length_mm,
y = bill_length_mm)) +
geom_point(aes(color = species,
shape = species))
``````r) between curly braces {r}#| (hashpipe): #| option1: valueTip for efficiency
Use a keyboard shortcut to create a new code chunk!
RStudio: Ctrl + Alt + I (OS X: Cmd + Option + I)
VS Code: Ctrl + Shift + I
Options for R code chunks: https://quarto.org/docs/reference/cells/cells-knitr.html
```{r}
#| output-location: column
#| label: fig-scatterplot
#| fig-cap: "Scatterplot of flipper and bill lengths"
#| warning: false
library(palmerpenguins) # for data
library(ggplot2) # for data visualization
ggplot(data = penguins,
aes(x = flipper_length_mm,
y = bill_length_mm)) +
geom_point(aes(color = species,
shape = species))
```Options for R code chunks: https://quarto.org/docs/reference/cells/cells-knitr.html
```{python}
#| output-location: column
#| label: fig-scatterplot-py
#| fig-cap: "Scatterplot of flipper and bill lengths in Python"
import numpy as np
import matplotlib.pyplot as plt
from palmerpenguins import load_penguins
penguins = load_penguins()
penguins['species_color'] = penguins['species']
penguins['species_color'].replace(['Adelie', 'Chinstrap', 'Gentoo'],
['red', 'green', 'blue'], inplace=True)
penguins.plot.scatter(x='flipper_length_mm',
y='bill_length_mm',
c='species_color')
```Options for Python code chunks: https://quarto.org/docs/reference/cells/cells-jupyter.html
| fruit | price |
|--------|-------|
| apple | 2.05 |
| pear | 1.37 |
| orange | 3.09 |
: Fruit prices {.striped .hover}| fruit | price |
|---|---|
| apple | 2.05 |
| pear | 1.37 |
| orange | 3.09 |
More information: https://quarto.org/docs/authoring/tables.html
```{r}
#| output-location: column
#| label: tbl-stats
#| tbl-cap: "Summary statistics for flipper and bill lengths"
penguins %>%
group_by(species) %>%
summarise(
`Mean bill length` = mean(bill_length_mm, na.rm = T),
`Mean flipper length` = mean(flipper_length_mm, na.rm = T),
`Correlation, r` = cor(flipper_length_mm, bill_length_mm, use = "complete")
) %>%
kable(digits = c(2, 2, 2, 2, 2))
```| species | Mean bill length | Mean flipper length | Correlation, r |
|---|---|---|---|
| Adelie | 38.79 | 189.95 | 0.33 |
| Chinstrap | 48.83 | 195.82 | 0.47 |
| Gentoo | 47.50 | 217.19 | 0.66 |
More information: https://quarto.org/docs/authoring/tables.html
```{python}
#| output-location: column
#| label: tbl-py
#| tbl-cap: "First rows of penguins dataframe"
from tabulate import tabulate
from IPython.display import Markdown
# Convert to markdown table
Markdown(tabulate(penguins[["species", "island", "bill_length_mm", "flipper_length_mm"]].head(), headers='keys', tablefmt='github'))
```| species | island | bill_length_mm | flipper_length_mm | |
|---|---|---|---|---|
| 0 | Adelie | Torgersen | 39.1 | 181 |
| 1 | Adelie | Torgersen | 39.5 | 186 |
| 2 | Adelie | Torgersen | 40.3 | 195 |
| 3 | Adelie | Torgersen | nan | nan |
| 4 | Adelie | Torgersen | 36.7 | 193 |
More information: https://quarto.org/docs/authoring/tables.html
The palmerpenguins package contains data for ` {r} nrow(penguins) ` penguins.
Remove the space before {r} to make sure the code is evaluated!The palmerpenguins package contains data for 344 penguins.
Warning
Inline code only works for the chosen engine (knitr: R; jupyter: Python). Specify the engine explicitly in the YAML header.
::: {.panel-tabset}
## Element 1
## Element 2
:::
This sentence ends with a footnote.1
and much more! https://quarto.org/docs/guide/
Converting temperature from ℃ to ℉
Celsius = ℃ and Fahrenheit = ℉.
Generated using this code chunk, text, and inline code:
.Rmd or .ipynb?For some of you - nothing changes! Keep using RMarkdown and Jupyter.
However, most existing .rmd or .ipynb can be rendered as-is via Quarto
Collaboration with other colleagues in other languages - shared format, choose your editor and your native language
Development of Quarto is sponsored by RStudio, PBC. The same core team works on both Quarto and R Markdown:
Carlos Scheidegger (@cscheid)
Charles Teague (@dragonstyle)
Christophe Dervieux (@cderv)
J.J. Allaire (@jjallaire)
Yihui Xie (@yihui)
Here is the full contributors list. Quarto is open source and they welcome contributions in their github repository as well! https://github.com/quarto-dev/quarto-cli.
The slides and materials for this workshop were heavily based on other existing guides and workshops:
Getting Started with Quarto by Tom Mock - CC BY 4.0
Quarto workshop by Julien Barnier and Aurélie Siberchicot
Icon attributions:
Thank you very much for providing these open resources!
Eline Van Geert
Postdoc researcher
Brain & Cognition
PPW, KU Leuven
Lisa Koßmann
PhD student
Brain & Cognition
PPW, KU Leuven